package com.sense.kukoo.biz_library.adapter.provider

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.sense.kukoo.biz_library.adapter.FollowTitleAdapter
import com.sense.kukoo.common.R
import com.sense.kukoo.common.repo.biz.FollowTitleItemBean
import com.sense.kukoo.common.repo.http.bean.UserSearchBean
import com.sense.kukoo.common.wiget.adapter.provider.MultiItemProvider
import com.sense.kukoo.common.wiget.adapter.viewholder.BaseViewHolder
import com.sense.kukoo.lib_picture.loader.Monet

class FollowTitleItemProvider(val listener: FollowTitleAdapter.FollowTitleEventListener): MultiItemProvider<FollowTitleItemBean>() {

    private val TAG: String = javaClass.simpleName

    override fun getItemType(): Int = 0

    override fun getItemLayoutId(): Int = R.layout.common_item_follow_title_item

    override fun onBindViewHolder(viewHolder: BaseViewHolder, item: FollowTitleItemBean) {
        val user: UserSearchBean = item.user
        val currentSelectedUser: UserSearchBean? = item.currentSelectedUser
        //
        val cl_follow_title_item_root = viewHolder.getView(R.id.cl_follow_title_item_root)
        val iv_icon_channel = viewHolder.getView(R.id.iv_icon_channel) as ImageView
        val iv_icon_channel_fg = viewHolder.getView(R.id.iv_icon_channel_fg) as ImageView
        val tv_name_channel = viewHolder.getView(R.id.tv_name_channel) as TextView
        //
        if(currentSelectedUser == null){
            iv_icon_channel_fg.visibility = View.GONE
            cl_follow_title_item_root.alpha = 1F
        } else {
            if(user.id == currentSelectedUser.id){
                iv_icon_channel_fg.visibility = View.VISIBLE
                cl_follow_title_item_root.alpha = 1F
            } else {
                iv_icon_channel_fg.visibility = View.GONE
                cl_follow_title_item_root.alpha = 0.5F
            }
        }
        //
        Monet.get(iv_icon_channel.context)
            .load<Any>(user.avatarUrl)
            .placeholder(com.sense.kukoo.common_design.R.drawable.design_icon_avatar_default)
            .circleCrop()
            .into(iv_icon_channel)
        tv_name_channel.text = user.channelName
        //
        iv_icon_channel.setOnClickListener {
            listener.onItemClick(user)
        }
    }
}